package main

import "fmt"

// 选择排序
// 将第一位依次与他的后几位进行比较并交换
// 将第二位依次与他的后几位进行比较并交换
// 依次类推
func selectOrder(arr []int) []int {
	if arr == nil || len(arr) < 2 {
		return arr
	}

	for i := 0; i < len(arr); i++ {
		var minIndex = i
		for j := i + 1; j < len(arr); j++ {
			if arr[i] > arr[j] {
				minIndex = j
			}
		}
		Swap(arr, i, minIndex)
	}

	return arr
}

func Swap(arr []int, i, j int) {
	//temp := arr[i]
	//arr[i] = arr[j]
	//arr[j] = temp
	arr[i], arr[j] = arr[j], arr[i]
}

func main() {
	fmt.Println(selectOrder([]int{1, 2, 3, 10, 9, 8, 6}))
	fmt.Println(selectOrder([]int{9, 8, 7, 7, 6, 8, 4}))
	fmt.Println(selectOrder([]int{100, 20, 6, 10, 9, 8, 6}))
}
